package com.auntvt.timo.jpax.core.service.impl;

import com.auntvt.timo.jpax.core.service.QuickService;
import com.auntvt.timo.jpax.core.utils.RepositoryUtil;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

/**
 * 整合Quick快速查询接口
 * <p>QuickService接口实现，对应JpaSpecificationExecutor接口的方法</p>
 *
 * @author 小懒虫 <auntvt@163.com>
 * @date 2021/7/31
 */
public class QuickServiceImpl<T> implements QuickService<T>, QuickServiceMulti<T> {

    /**
     * 对应实体类的持久层Repository
     */
    protected JpaSpecificationExecutor<T> repository;

    /**
     * 获取对应实体类的持久层Repository接口
     *
     * @return Repository接口
     */
    @Override
    @SuppressWarnings("unchecked")
    public JpaSpecificationExecutor<T> getRepository() {
        if (repository == null) {
            repository = RepositoryUtil.getMatchRepository(JpaSpecificationExecutor.class, this.getClass());
        }
        return repository;
    }
}
